import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';


class SharePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("分享")),
      body: ListView(
        children: [
          TextButton(
            onPressed: () {
              Share.share("share text 123");
            },
            child: const Text("分享文本"),
          ),
          TextButton(
            onPressed: () async {
              final result = await FilePicker.platform.pickFiles();
              if (result == null || result.files.isEmpty) {
                print("未选择文件!");
                return;
              }

              final paths = result.files.map((e) => e.path);
              Share.shareXFiles(paths.map((e) => XFile(e!)).toList());
            },
            child: const Text("分享文件(先选择文件，再分享)"),
          )
        ],
      ),
    );
  }
}
